|
|
 |
|
|
|
|
oObject.Show
ElseIf TypeOf oObject is TimeSheet
oObject.Display
ElseIf TypeOf oObject is EmpType
oObject.Draw
End If
Next |
|
|
|
|
|
|
|
|
Not only is this code more difficult to read, its also much slower to execute because Visual Basic is forced to perform type checking against each of the different types of objects. |
|
|
|
|
|
|
|
|
Converting to Object-based Programming |
|
|
|
|
|
|
|
|
The hardest part of learning object programming is not the terminology or writing code. You can learn the new words, and writing code youve probably been doing for years. Whats not so easy is deciding what should be a class and what should not. To help you make the decision, you can follow a few methods to identify objects. |
|
|
|
|
|
|
|
|
Converting Existing Projects |
|
|
|
|
|
|
|
|
The first method involves looking at an existing Visual Basic projects that was developed procedurally. Find some global variables that all have some relationship to one another. Then find those functions that use those global variables. Chances are that the global variables can become properties of a class, and the public procedures that operate upon those global variables can become the methods. |
|
|
|
|
|
|
|
|
Replacing User-defined Types |
|
|
|
|
|
|
|
|
Another method also looks at an existing project. If youve ever used user-defined types, youll know that these are very similar to objects. The only difference is that the user-defined type is just the data (properties). You then need to find the functions that utilize this user-defined type, and you should be able to combine both of these items into one class. |
|
|
|
|
|
|
|
|
The last method of determining what should be a class involves looking at global variables that are just used to pass information from one form to another. If you have this situation, you can now make properties on forms so that you can pass data from one form to another. |
|
|
|
|
|